package naruto.datastructures.graph;

import java.util.*;
import naruto.datastructures.instruction.*;

/**
 *
 * @author nacuong
 */
public class EndIfNode extends IfCompleteNode<EndIfInstruction>{
  public EndIfNode(EndIfInstruction endIfInstruction){
    super(endIfInstruction);
  }

  public EndIfNode(EndIfInstruction endIfInstruction, Vector<Edge> endIfEdges){
    super(endIfInstruction, endIfEdges);
  }

  /**
   * Check whether this endif node is an endloop node.
   * This method first find the coressponding if node of this endif.
   * It then checks whether the corresponding if node is a loop node.
   * @param model
   * @return
   */
  public boolean isEndForLoopNode(IfCompleteModel model){
    return getIfNode(model).isLoopNode();
  }

  /**
   * Get the corresponding if node of this endif node
   * @param model
   * @return
   */
  public IfNode getIfNode(IfCompleteModel model){
    IfInstruction ifInstruction = new IfInstruction(this.getInstruction().getInstruction());
    IfNode ifNode = (IfNode) model.getNode(ifInstruction);
    return ifNode;
  }
}
